﻿using IceDog.Uop.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace IceDog.Uop.Models.Context
{
    public class UopContext : DbContext
    {
        public UopContext(DbContextOptions<UopContext> options) : base(options)
        {

        }

        public DbSet<Order> Orders { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<OrderDetail> OrderDetails { get; set; }

        /// <summary>
        /// 模型创建的时候
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Order>().ToTable("uop_order");
            modelBuilder.Entity<Product>().ToTable("uop_product");
            modelBuilder.Entity<User>().ToTable("uop_user");
            modelBuilder.Entity<OrderDetail>().ToTable("uop_order_detail");
            modelBuilder.Entity<OrderDetail>()
                .HasKey(e => new { e.OrderId,e.ProductId});
        }
    }
}
